package com.zmn.oms.admin.controller.work.modify;

import com.zmn.oms.admin.controller.OmsBaseController;
import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.model.dto.work.modify.OrderWorkTagDTO;
import com.zmn.oms.model.vo.work.modify.OrderTagVO;
import com.zmn.oms.zmn.normal.business.interfaces.work.OrderWorkTagBService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 类描述：工单标记
 *
 * @author liuying
 * @date 2021/08/19 13:54
 */
@Slf4j
@Controller
@RequestMapping("/work/modify")
public class WorkTagController extends OmsBaseController {

    @Autowired
    private OrderWorkTagBService orderWorkTagBService;

    /**
     * 标记
     */
    @RequestMapping(value = "/ordertag")
    public ModelAndView mark(Long orderId, Long workId) {
        ModelAndView mv = new ModelAndView("work/modify/ordertag");
        OrderTagVO orderTagVO = orderWorkTagBService.getOrderTagVO(orderId, workId);

        mv.addObject("orderTagVO", orderTagVO);
        return mv;
    }

    /**
     * 保存标记
     */
    @ResponseBody
    @RequestMapping(value = "/save/ordertag")
    public ResultDTO saveMark(@RequestBody OrderWorkTagDTO orderWorkTagDTO) {
        try {
            orderWorkTagBService.saveOrderTag(orderWorkTagDTO);
        } catch (OmsBaseException e) {
            ResultDTO.fail(e.getMessage());
        }catch (Exception e) {
            log.error(e.getMessage(), e);
            ResultDTO.fail(e.getMessage());
        }
        return ResultDTO.success();
    }

}